#include "PreComplie.h"
#include "MainWin.h"

static LRESULT __stdcall WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_CLOSE:
		PostQuitMessage(0);
		return 0;
	default:
		return DefWindowProcW(wnd, msg, wParam, lParam);
	}
}

HWND CreateMainWin(HINSTANCE hInstance)
{
	WNDCLASSW wndClass;
	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc = WndProc;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hInstance = hInstance;
	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
	wndClass.lpszMenuName = NULL;
	wndClass.lpszClassName = L"TestWindowClass";

	if(RegisterClassW(&wndClass) == 0)
		goto Error;

	DWORD wndStyle = WS_OVERLAPPED | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE;
	HWND wnd = CreateWindowW(L"TestWindowClass", L"TestWindow", wndStyle, 200, 100, 800, 600, NULL, NULL, hInstance, NULL);
	if(!wnd)
		goto Error;
	else
		return wnd;

Error:
	MessageBoxW(NULL, L"RegisterClassFailed", L"Error", MB_OK);
	return NULL;
}
